package com.unitedats.HR.Servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.unitedats.HR.Entity.HrDepartment;
import com.unitedats.common.Servlet.BasicServlet;
import com.unitedats.common.bo.Message;
import com.unitedats.common.util.DateUtil;
import com.unitedats.common.util.WebUtil;

public class DepartmentDeleteProcessServlet extends BasicServlet {

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		// String dest = WebUtil.getParamValue(request, "dest",
		// "DepartmentAddDisplay");

		int deletedNodeId = WebUtil.getParamValueAsInteger(request, "deletedNodeId", 0);
		HrDepartment dep = dbm.findById(deletedNodeId, HrDepartment.class);

		if (dep != null) {
			dep.setStatus(false);
			dep.setLastModifiedIn(DateUtil.getCurrentDate());
			dep.setLastModifiedBy(getSessionUser(request).getEmpId());
			dbm.mergeEntity(dep);
		}

		setMessage(request, new Message("Department has been deleted successfuly", Message.MESSAGE_TYPE.SUCCESS));
		sendRedirect(request, response, "DepartmentUpdateDisplay");// dest);
	}
}
